﻿using System;
using System.IO;
using Gtk;

namespace MonoFM.Gui
{
    [System.ComponentModel.ToolboxItem(true)]
    class SingleFilePanel : FmPanel
    {
        private FileView _fileView;

        private ScrolledWindow _scroller;

        internal SingleFilePanel()
        {
            Console.WriteLine("Single File Panel");
            this.Build();
        }

        private void Build()
        {
            Stetic.BinContainer.Attach(this);
            _fileView = new FileView();
            _scroller = new ScrolledWindow {_fileView};

            var store = new NodeStore(typeof(FileNode));
            var currentDirectory = Directory.GetCurrentDirectory();
            var files = Directory.GetFileSystemEntries(currentDirectory);
            _fileView.Shown += FmEventHandler.OnFilePanelShown;

            var parentFileNode = new FileNode("..", 0);
            store.AddNode(parentFileNode);
            foreach (var fileName in files)
            {
                var fileNode = new FileNode(new FileInfo(fileName).Name, 0);
                store.AddNode(fileNode);
            }

            _fileView.NodeStore = store;
            _fileView.HeadersVisible = true;

            _fileView.AppendColumn("Name", new CellRendererText(), "text", 0);
            _fileView.AppendColumn("Size", new CellRendererText(), "text", 1);

            Add(_scroller);


            if ((Child != null))
            {
                Child.ShowAll();
            }
            Show();
        }

        private void _fileView_Shown(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
    }
}
